<?php  
class ControllerModuleSlideshow extends Controller {
	protected function index($setting) {
		static $module = 0;
		
		$this->load->model('design/banner');
		$this->load->model('tool/image');
		
		$this->document->addScript('catalog/view/javascript/jquery/nivo-slider/jquery.nivo.slider.pack.js');
		$this->document->addStyle('catalog/view/javascript/jquery/nivo-slider/nivo-slider.css');
		
		$this->data['banners'] = array();
		$width = $setting['width'];
		$height = $setting['height'];
		if (isset($setting['width_s'])){
			$width_s = $setting['width_s'];
		}else{
			$width_s = 0;
		}
		if (isset($setting['height_s'])){
			$height_s = $setting['height_s'];
		}else{
			$height_s = 0;
		}
			
		if (isset($setting['banner_id'])) {
			$results = $this->model_design_banner->getBanner($setting['banner_id']);
			$rl = count($results);
			if (!isset($setting['width_s'])){
				$width_s = floor($width / $rl);
			}
			if (!isset($setting['height_s'])){
				$height_s = floor($height / $rl);
			}
			foreach ($results as $result) {
				if($setting['navType'] == 3){
					$imaUrl = $result['image'];
					$img_i = strrpos($imaUrl,".");
					$imaUrl_nav = substr($imaUrl, 0, $img_i) . "_nav" . substr($imaUrl, $img_i);
					if (file_exists(DIR_IMAGE . $imaUrl)) {
						if (!file_exists(DIR_IMAGE . $imaUrl_nav)){
							$imaUrl_nav = $imaUrl;
						}
						$this->data['banners'][] = array(
							'title' => $result['title'],
							'link'  => $result['link'],
							'image' => $this->model_tool_image->resize($imaUrl, $width, $height),
							'image_nav' => $this->model_tool_image->resize($imaUrl_nav, $width_s, $height_s)
						);
					}
				}else{
					$width_s = 0;
					$height_s = 0;
					if (file_exists(DIR_IMAGE . $result['image'])) {
						$this->data['banners'][] = array(
							'title' => $result['title'],
							'link'  => $result['link'],
							'image' => $this->model_tool_image->resize($result['image'], $width, $height)
						);
					}
				}
			}
		}
		
		$this->data['width'] = $width;
		$this->data['height'] = $height;
		$this->data['width_s'] = $width_s;
		$this->data['height_s'] = $height_s;
		$this->data['navType'] = $setting['navType'];
		$this->data['module'] = $module++;
						
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/slideshow.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/slideshow.tpl';
		} else {
			$this->template = 'default/template/module/slideshow.tpl';
		}
		
		$this->render();
	}
}
?>